home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Install
- BackColor = &H00C0C0C0&
- Caption = "Install"
- ClientHeight = 2745
- ClientLeft = 1245
- ClientTop = 2880
- ClientWidth = 7245
- Height = 3150
- Icon = VBINST.FRX:0000
- Left = 1185
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- ScaleHeight = 2745
- ScaleWidth = 7245
- Top = 2535
- Width = 7365
- Begin DirListBox Dir1
- Height = 315
- Left = 2175
- TabIndex = 3
- Top = 2325
- Visible = 0 'False
- Width = 915
- End
- Begin CommandButton Cmd_Start
- Caption = "&Start"
- Default = -1 'True
- Height = 540
- Left = 6150
- TabIndex = 8
- Top = 2025
- Width = 990
- End
- Begin CheckBox Check1
- BackColor = &H00C0C0C0&
- Caption = "&OK to create?"
- ForeColor = &H00000000&
- Height = 390
- Left = 150
- TabIndex = 10
- Top = 2025
- Width = 1890
- End
- Begin CommandButton Cmd_Cancel
- Cancel = -1 'True
- Caption = "&Cancel"
- Height = 540
- Left = 6150
- TabIndex = 7
- Top = 1350
- Width = 990
- End
- Begin ListBox List1
- BackColor = &H00C0C0C0&
- ForeColor = &H00000000&
- Height = 1005
- Left = 2250
- TabIndex = 4
- Top = 1275
- Width = 3090
- End
- Begin Frame Fr_Dest
- Caption = "D&estination SubDirectory"
- Height = 660
- Left = 3525
- TabIndex = 6
- Top = 75
- Width = 3015
- Begin TextBox Txt_Dest
- ForeColor = &H00000000&
- Height = 315
- Left = 75
- TabIndex = 0
- Top = 300
- Width = 2865
- End
- End
- Begin Frame Fr_Drive
- BackColor = &H00C0C0C0&
- Caption = "&Destination Disk"
- Height = 660
- Left = 675
- TabIndex = 1
- Top = 75
- Width = 2760
- Begin DriveListBox Drive1
- ForeColor = &H00000000&
- Height = 315
- Left = 75
- TabIndex = 2
- Top = 300
- Width = 2295
- End
- End
- Begin Label Label1
- BackColor = &H00C0C0C0&
- Caption = "Do you want install to create own Program Manager Group?"
- ForeColor = &H00000000&
- Height = 615
- Left = 150
- LinkTimeout = 10
- TabIndex = 9
- Top = 1350
- Width = 1890
- End
- Begin Label Lbl_List
- Alignment = 2 'Center
- BackColor = &H00C0C0C0&
- Height = 315
- Left = 1500
- TabIndex = 5
- Top = 900
- Visible = 0 'False
- Width = 4515
- End
- Function CheckDir (Chk As Integer) As Integer
- '**********************************************************************
- '* Check destination directory, that it does not exceed allowed *
- '* 11 characters (8+3).If user gives directory such as "..\myprogram",*
- '* which has 9 characters in body part, Visual Basic does not *
- '* generate an error code. VB just cut chrs exceeding 8 limit from *
- '* left. So "..\myprogram " would be "..\myprogra", but in Program *
- '* Manager Group item path is still "..\myprogram ", which would cause*
- '* error runing the istalled program. *
- '* To find first "\" (backslash) from right, *
- '* we need to examine destination path string in reverse order *
- '* For example "D:\WINDOWS\VBINST" would be "TSNIBV\SWODNIW\:D". *
- '* Now we can use InStr function to find first occurence of "\" *
- '* in destination path and check the destination directory. *
- '**********************************************************************
- DirLen% = Len(Txt_Dest.Text)
- For J% = DirLen% To 1 Step -1
- Temp$ = Mid$(Txt_Dest.Text, J%, 1)
- Directory$ = Directory$ + Temp$
- Next
- 'Get destination SubDirectory string
- 'Get directory's extension if exist
- 'Get directory's bodypart
- Directory$ = Left$(Directory$, (InStr(Directory$, "\")))
- Extension% = InStr(Directory$, ".")
- BodyPart% = InStr(Directory$, "\") - Extension%
- 'Check extension to not exceed 3 chrs
- If (Extension% = 0 Or Extension% < 5) Then
- 'if not extension exceed 3, check bodypart to not exceed 8 chrs
- If BodyPart% > 9 Then
- Chk = 0
- Else
- Chk = 2
- End If
- Else
- Chk = 1
- End If
- End Function
- Sub Cmd_Cancel_Click ()
- Const IDYES = 6 'define msgbox return value
- If Cmd_Cancel.Caption = "&Cancel" Then
- Msg$ = "Are you sure you want to cancel install?" 'give the user a second change
- Title$ = "CANCEL???"
- Response% = MsgBox(Msg$, 292, Title$) ' Get user response. '36+4+256
- If Response% = IDYES Then ' Evaluate response
- Else
- Exit Sub
- End If
- End If
- End Sub
- Sub Cmd_Start_Click ()
- Dim ErrDirTitle As String
- ErrDirTitle$ = "Error creating SubDirectory"
- 'Set Flag for checking files overwrit
- WarnFlag = True
- 'assign drive to DestDrive variable for checking needed free diskspace
- DestDrive$ = Left$(LCase$(Txt_Dest.Text), 1)
- 'see Function NeedSpace in general section
- RetValue% = NeedSpace(Chk%)
- If Chk% = False Then Exit Sub 'not enough diskspace
- 'Check destination directory's number of characters.
- 'See Function CheckDir in general procedure
- RetValue% = CheckDir(Chk%)
- If Chk% = 0 Then
- Msg$ = "Directory's bodypart exceeded 8 characters"
- MsgBox Msg$, 16, ErrDirTitle$
- Txt_Dest.Text = LCase$(LoadDir$) 'change back to default dir drive
- Exit Sub
- ElseIf Chk% = 1 Then
- Msg$ = "Directory's extension exceeded 3 characters"
- MsgBox Msg$, 16, ErrDirTitle$
- Txt_Dest.Text = LCase$(LoadDir$) 'change back to default dir drive
- Exit Sub
- End If
- On Error Resume Next 'Set up error handling.
- DestDir$ = LCase$(Txt_Dest.Text) 'Make path specification.
- twobs% = InStr(DestDir$, "\\") 'check if user has put accidently two backslash
- If twobs% <> 0 Then 'into subdirectory's name
- Msg$ = "SubDirectory has 2 (\\) backslash! "
- MsgBox Msg$, 16, ErrDirTitle$
- Txt_Dest.Text = LCase$(LoadDir$) 'change back to default dir drive
- Drive1.Drive = Left$(WD$, 1)
- Exit Sub
- ChDir DestDir$ 'check if directory already exist
- If Err = 76 Or Err = 0 Then 'see error values
- Err = 0 'reset err
- MkDir DestDir$ 'make directory
- If Err = 76 Then 'wrong directory name
- Msg$ = "Could not create such SubDirectory!, Check the SubDirectory's name."
- MsgBox Msg$, 16, ErrDirTitle$
- Txt_Dest.Text = LCase$(LoadDir$) 'change back to default dir drive
- Drive1.Drive = Left$(WD$, 1)
- Exit Sub
- End If
- End If
- End If
- 'change back to source directory
- ChDir SD$
- 'start installing job
- Install.Refresh
- Lbl_List.Visible = True
- List1.Refresh
- Lbl_List.Refresh
- 'get files from install.inf using GetPrivateProfileString API call
- 'to be copied windows system dir
- lpApplication$ = "SystemFiles"
- lpDefault$ = "EndMark"
- lpKeyName$ = "file"
- SubDir$ = WSD$
- IniCopy lpApplication$, lpKeyName$, lpDefault$, SubDir$
- 'get files from install.inf using GetPrivateProfileString API call
- 'to be copied desired subdir
- lpApplication$ = "Files"
- lpKeyName$ = "file"
- lpDefault$ = "EndMark"
- SubDir$ = DestDir$
- IniCopy lpApplication$, lpKeyName$, lpDefault$, SubDir$
- 'hides install form
- Install.Hide
- 'create a program manager group if check1 is checked
- If Install.Check1.Value = 1 Then
- lpApplication$ = "Def"
- lpDefault$ = ""
- lpKeyName$ = "defgroup"
- GetStringvar% = GetPrivateProfileString(lpApplication$, lpKeyName$, lpDefault$, FileStr$, nSize%, lpFileName$)
- DestGroup$ = RTrim$(Left$(FileStr$, GetStringvar%))
- Err = 0
- 'use DDE conversation with Program Manager to create
- 'group and program item
- Label1.LinkTopic = "PROGMAN|PROGMAN"
- Label1.LinkMode = 2
- Label1.LinkExecute "[DeleteGroup(" + DestGroup$ + ")]"
- 'use LinkRequest to force windows shell
- 'do the DDE conversation (should disable conflicts
- 'if group alrady exist)
- Label1.LinkRequest
- 'reset error
- Err = 0
- Label1.LinkExecute "[CreateGroup(" + DestGroup$ + ")]"
- Label1.LinkRequest
- Label1.LinkExecute "[ShowGroup(" + DestGroup$ + ")]"
- 'Add files to Program Manager group we just created
- lpApplication$ = "GrpFiles"
- lpDefault$ = "EndMark"
- 'start loop
- I = 0
- Do
- I = I + 1
- lpKeyName$ = "file" + Str$(I)
- GetStringvar% = GetPrivateProfileString(lpApplication$, lpKeyName$, lpDefault$, FileStr$, nSize%, lpFileName$)
- 'get only characters from FileStr$ (see form load procedure)
- DestPrg$ = DestDir$ + "\" + RTrim$(Left$(FileStr$, GetStringvar%))
- 'check named mark to end loop
- If Left$(FileStr$, 7) = "EndMark" Then
- Exit Do
- ElseIf Left$(FileStr$, 8) = "EndMark" Then
- Exit Do
- End If
- Label1.LinkExecute "[AddItem(" + DestPrg$ + ")]"
- Loop
- 'close DDE chanel
- Label1.LinkMode = 0
- 'if install is succesful let them know
- If Not Err Then
- Msg$ = "Installation succesfull!"
- Title$ = DestGroup$
- MsgBox Msg$, 64, Title$
- AppActivate "Install"
- Else
- Msg$ = "Installation Error on creating Program Manager Group!"
- Title$ = DestGroup$
- MsgBox Msg$, 16, Title$
- AppActivate "Install"
- End If
- Msg$ = "Installation succesfull!"
- Title$ = "Install"
- MsgBox Msg$, 64, Title$
- AppActivate "Install"
- End
- End If
- End Sub
- Sub Dir1_Change ()
- 'Change the default dir to windows dir
- 'check if windows logged drive and dir is
- 'drive where windows resides
- a$ = LCase$(Left$(Drive1.Drive, 1))
- B$ = LCase$(Left$(WD$, 1))
- If a$ = B$ Then
- DestDir$ = LCase$(WD$)
- Else
- DestDir$ = LCase$(Dir1.path)
- End If
- 'get default dir using API call (see Cmd_Start)
- lpApplication$ = "Def"
- lpDefault$ = ""
- lpKeyName$ = "defdir"
- GetStringvar% = GetPrivateProfileString(lpApplication$, lpKeyName$, lpDefault$, FileStr$, nSize%, lpFileName$)
- 'default directory
- 'if user changes drive and current dir is the root dir
- 'we don't put the backslash into pathname
- If Right$(DestDir$, 1) = "\" Then
- Txt_Dest.Text = DestDir$ + FileStr$
- Else
- Txt_Dest.Text = DestDir$ + "\" + FileStr$
- End If
- End Sub
- Sub Drive1_Change ()
- 'in case user accidently changes to drive which is
- 'unavailable program changes back to windows drive
- On Error Resume Next
- Dir1.path = Drive1.Drive
- If Err Then
- Dir1.path = LCase$(WD$)
- Drive1.Drive = Left$(WD$, 1)
- End If
- End Sub
- Sub Form_Load ()
- Dim WD1 As String * 128 'win directory, because of DLL's return
- Dim WSD1 As String * 128 'system directory, because of DLL's return
- nWSize% = 128
- nSSize% = 128
- nSize% = 128 'give max size of string to return in GetPrivateprofileString
- 'hide wait form
- Wait.Hide
- ' Center on the screen
- '
- Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
- 'Apply windows Desktop color to objects
- Install.BackColor = WINDOW_BACKGROUND
- Fr_Drive.BackColor = APPLICATION_WORKSPACE
- Fr_Dest.BackColor = APPLICATION_WORKSPACE
- List1.BackColor = APPLICATION_WORKSPACE
- Label1.BackColor = APPLICATION_WORKSPACE
- Check1.BackColor = APPLICATION_WORKSPACE
- Txt_Dest.ForeColor = WINDOW_TEXT
- Drive1.ForeColor = WINDOW_TEXT
- Check1.ForeColor = WINDOW_TEXT
- List1.ForeColor = WINDOW_TEXT
- Label1.ForeColor = WINDOW_TEXT
- ' Get source drive and dir, Windows dir and System dir
- 'by default install create it's own Program Manager Group
- Install.Check1.Value = 1
- SD$ = LCase$(CurDir$) 'Source directory
- If Right$(SD$, 1) = "\" Then
- SD$ = SD$
- Else
- SD$ = SD$ + "\"
- End If
- Wdir% = GetWindowsDirectory(WD1$, nWSize%)'windir
- Sdir% = GetSystemDirectory(WSD1$, nSSize%)'systemdir
- 'only value returning Wdir% and Sdir% are accepted
- 'etc. if Wdir%'s value is 7 we read 7 chars from left
- ' global windows and system directory with leading spaces cutted off (RTrim$)
- WD$ = RTrim$(LCase$(Left$(WD1$, Wdir%)))
- WSD$ = RTrim$(LCase$(Left$(WSD1$, Sdir%)))
- 'get default dir from install.inf using API call (see Cmd_Start)
- 'name lpFileName
- lpFileName$ = SD$ + "install.inf"
- lpApplication$ = "Def"
- lpDefault$ = ""
- lpKeyName$ = "defdir"
- GetStringvar% = GetPrivateProfileString(lpApplication$, lpKeyName$, lpDefault$, FileStr$, nSize%, lpFileName$)
- 'default directory
- Txt_Dest.Text = WD$ + "\" + FileStr$
- LoadDir$ = WD$ + "\" + FileStr$
- Drive1.Drive = Left$(WD$, 1) + ":"
- End Sub
- Function NeedSpace (Chk As Integer) As Integer
- 'get needed diskspace from install.inf using API call GetPrivateProfileInt
- lpApplication$ = "Def"
- nDefault% = 0
- lpKeyName$ = "needspace"
- GetStringvar% = GetPrivateProfileInt(lpApplication$, lpKeyName$, nDefault%, lpFileName$)
- '*********************************************************************
- '* convert DestDrive$ letter to equivalent in number *
- '* eg. c=3, d=4 and so on.. *
- '* if Asc(DestDrive$) is 99 which is ASCII numeric value for "c", *
- '* we do subtraction from numeric value c (99-96=3), because DFree *
- '* function assign drive as number 1=a, 2=b, 3=c and so on. *
- '* I don't know if there is any function in VB, that directly convert*
- '* alphabets to numeric value! Hit me with E-mail if you come up with*
- '* such as function! Thanks! *
- '*********************************************************************
- Disk% = Asc(DestDrive$) - 96 'drive ASCII value minus 96
- FreeSpace = DFree(Disk%) \ 1024 'in KiloBytes
- 'do the checking
- If FreeSpace < GetStringvar% Then
- Chk% = False
- Msg$ = "Not enough free DiskSpace in specified drive!"
- Msg$ = Msg$ + Chr$(13) + Chr$(10) + "DiskSpace available: " + Str$(FreeSpace) + "KB"
- Msg$ = Msg$ + Chr$(13) + Chr$(10) + "DiskSpace needed : " + Str$(GetStringvar%) + "KB"
- Msg$ = Msg$ + Chr$(13) + Chr$(10) + "1. Try another drive"
- Msg$ = Msg$ + Chr$(13) + Chr$(10) + " OR"
- Msg$ = Msg$ + Chr$(13) + Chr$(10) + "2. Cancel install and free some DiskSpace"
- Title$ = "WARNING!"
- MsgBox Msg$, 16, Title$
- Else
- Chk% = True
- End If
- End Function
-